# -*- coding: utf-8 -*-
# @Time : 2022/2/24 9:18
# @Author : Administrator
# @Email : simple_days@qq.com
# @File : userManageDao.py.py
# @Project : backend
# ©Copyright : 中国电建集团透平科技有限公司版权所有

from asset.utils.mongoDBManage import get_mongo_collection,get_mongo_database
# userJson = {
#     "id":1,
#     "用户名":"张三",
#     "工作组":"离心|动调|静调",
#     "用户状态":"正常|离职|实习"
# }
from loguru import logger
def create(username,group='设计咨询部',status='正常'):
    userJson = {
        "id": 1,
        "用户名": username,
        "工作组": group,
        "用户状态": status
    }

    logger.debug(userJson)
    collection = get_mongo_collection('test')
    logger.debug(collection)

    logger.info(collection.insert_one(userJson))
    logger.info(collection.count_documents({}))

def getAll():
    logger.debug("查询所有用户")
    database = get_mongo_database('pcttTest')
    user_collection = database['user']

    userlist = list(user_collection.find({},{'_id':0}))
    logger.debug(userlist)
    total = len(userlist)
    logger.debug(f'获得的总数是{total}')
    return userlist,total

def getUserbyId(id):
    logger.debug(f"通过{id}查询用户")
    database = get_mongo_database('pcttTest')
    user_collection = database['user']

    # user = list(user_collection.find({'id':id}, {'_id': 0}))
    filter = {'id':int(id)}
    user = user_collection.find_one(filter,{'_id': 0})
    logger.debug(f'查询到用户id{id}的用户{user} filter:{filter}')
    return user


if __name__ == '__main__':
    create('张三')
    

